package main

import (
	"fmt"
	"log"
	"one-web/app/pkg/config"

	"github.com/gin-gonic/gin"
)

type User struct {
	Name  string `json:"name" form:"name"`
	Email string `json:"email" form:"email"`
}

func main() {
	r := gin.Default()
	r.GET("/hello/:id", func(c *gin.Context) {
		id := c.Param("id")
		c.JSON(200, gin.H{
			"message": "hello world",
			"id":      id,
		})
	})

	r.POST("/user/:id", func(c *gin.Context) {
		u := User{}

		ip := c.ClientIP()
		host := c.GetHeader("Host")
		fmt.Print(host)
		if c.ShouldBind(&u) == nil {
			log.Println(u.Name)
			log.Println(u.Email)
			log.Println("ip:", ip)

		}
		c.String(200, "Success")
	})

	r.Run(fmt.Sprintf("%s:%d", config.Server.Address, config.Server.Port))
}
